//
//  ReportVC.m
//  efairy
//  报表列表 和 生成报表之项目列表
//  Created by 李锋 on 2019/3/11.
//  Copyright © 2019年 East. All rights reserved.
//  资料：https://blog.csdn.net/hmt20130412/article/details/34523235
//

#import "ReportVC.h"
#import "ReportProjectListVC.h"
#import "ReportListVC.h"
#import "ReportProjectListVC.h"

@interface ReportVC ()
@property(nonatomic,strong)UIButton *projectBtn;
@property(nonatomic,strong)UIView *projectTitleLine;
@property(nonatomic,strong)UIButton *reportListBtn;
@property(nonatomic,strong)UIView *reportListTitleLine;
@property(nonatomic,strong)ReportListVC *reportListVC;
@property(nonatomic,strong)ReportProjectListVC *reportProjectListVC;

@property (nonatomic ,strong) UIViewController *currentVC;


@end

@implementation ReportVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBar];
    [self initView];
}

- (BOOL)hidesBottomBarWhenPushed{
    return YES;
}

-(void)setNavigationBar{
    self.navigationItem.title=@"报表";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"global_nav_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backVC)];
}


- (void)backVC {
    //返回上一界面
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)initView{
//    self.view.backgroundColor = ColorFromRGB(0xeff0f4);
    float barHeight = self.navigationController.navigationBar.frame.size.height;
    _projectBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, barHeight+statusBarHeight, SCREEN_WIDTH/2, 40)];
    [_projectBtn setTitle:@"报告列表" forState:UIControlStateNormal];
    [_projectBtn setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
    _projectBtn.titleLabel.font = [UIFont systemFontOfSize:15.f];
    _projectBtn.backgroundColor = [UIColor whiteColor];
    [_projectBtn addTarget:self action:@selector(onClickReportListBtn) forControlEvents:UIControlEventTouchUpInside];
    
    
    _reportListBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, barHeight+statusBarHeight, SCREEN_WIDTH/2, 40)];
    [_reportListBtn setTitle:@"生成报告" forState:UIControlStateNormal];
    [_reportListBtn setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
    _reportListBtn.titleLabel.font = [UIFont systemFontOfSize:15.f];
    _reportListBtn.backgroundColor = [UIColor whiteColor];
    [_reportListBtn addTarget:self action:@selector(onClickProjectBtn ) forControlEvents:UIControlEventTouchUpInside];
   
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, barHeight+statusBarHeight+41, SCREEN_WIDTH, 1)];
    line.backgroundColor  = ColorFromRGB(0xe5e5e5);
    _projectTitleLine = [[UIView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH/2-60)/2, barHeight+statusBarHeight+40, 60, 2)];
    _projectTitleLine.backgroundColor = ColorFromRGB(0x282449);
    _reportListTitleLine = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+(SCREEN_WIDTH/2-60)/2, barHeight+statusBarHeight+40, 60, 2)];
    _reportListTitleLine.backgroundColor = ColorFromRGB(0x282449);
    _reportListTitleLine.hidden = YES;
    
    
    [self.view sd_addSubviews:@[_projectBtn,_reportListBtn,line,_projectTitleLine,_reportListTitleLine]];
    
    self.reportListVC = [[ReportListVC alloc]init];
    [self.reportListVC.view setFrame:CGRectMake(0, barHeight+statusBarHeight+42, SCREEN_WIDTH, SCREEN_HEIGHT-barHeight-statusBarHeight-40)];
    [self addChildViewController:_reportListVC];
   
    //  默认,第一个视图(你会发现,全程就这一个用了addSubview)
    [self.view addSubview:self.reportListVC.view];
     self.currentVC = self.reportListVC;

}

-(void)onClickProjectBtn{
    if (self.currentVC == self.reportProjectListVC) {
        return;
    }
    [_projectBtn setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
    [_reportListBtn setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
    _projectTitleLine.hidden = YES;
    _reportListTitleLine.hidden = NO;
    if(self.reportProjectListVC == nil){
        float barHeight =  self.navigationController.navigationBar.frame.size.height;
        self.reportProjectListVC = [[ReportProjectListVC alloc]init];
        [self.reportProjectListVC.view setFrame:CGRectMake(0, barHeight+statusBarHeight+42, SCREEN_WIDTH, SCREEN_HEIGHT-barHeight-statusBarHeight-40)];
    }
    [self replaceController:self.currentVC newController:self.reportProjectListVC];
}

-(void)onClickReportListBtn{
    if (self.currentVC == self.reportListVC) {
        return;
    }
    [_projectBtn setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
    [_reportListBtn setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
    _projectTitleLine.hidden = NO;
    _reportListTitleLine.hidden = YES;
    [self replaceController:self.currentVC newController:self.reportListVC];
    
}



//  切换各个标签内容
- (void)replaceController:(UIViewController *)oldController newController:(UIViewController *)newController
{
    /**
     *            着重介绍一下它
     *  transitionFromViewController:toViewController:duration:options:animations:completion:
     *  fromViewController      当前显示在父视图控制器中的子视图控制器
     *  toViewController        将要显示的姿势图控制器
     *  duration                动画时间(这个属性,old friend 了 O(∩_∩)O)
     *  options                 动画效果(渐变,从下往上等等,具体查看API)
     *  animations              转换过程中得动画
     *  completion              转换完成
     */
  
[self addChildViewController:newController];
[self transitionFromViewController:oldController toViewController:newController duration:2.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) {
    
        if (finished) {
            
            [newController didMoveToParentViewController:self];
            [oldController willMoveToParentViewController:nil];
            [oldController removeFromParentViewController];
            self.currentVC = newController;
            
        }else{
            
            self.currentVC = oldController;
            
        }
    }];
}


-(void)onClickAddressView:(id)tap{
    NSLog(@"onClickAddressView");
}





-(void)queryReportList:(BOOL)isHeade{
    
}


@end
